// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "MoveLine.generated.h"

class UImage;
class UButton;

struct FLine
{
	FVector2D Start = FVector2D(0.0, 0.0);;

	FVector2D End = FVector2D(0.0, 0.0);;

	bool bValid = false;
};

/**
 * 
 */
UCLASS()
class UPPERCOMPUTER_API UMoveLine : public UUserWidget
{
	GENERATED_BODY()
	
protected:

	virtual void NativeConstruct() override;

	virtual void NativeTick(const FGeometry& MyGeometry, float InDeltaTime) override;

	virtual int32 NativePaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const override;

	virtual FReply NativeOnMouseButtonDown(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent) override;

	virtual FReply NativeOnMouseMove(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent) override;

	virtual FReply NativeOnMouseButtonUp(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent) override;

	UPROPERTY(meta = (BindWidget))
	TObjectPtr<UImage> Img;

	UPROPERTY(meta = (BindWidget))
	TObjectPtr<UButton> Btn;

private:

	bool bDragging = false;

	//绘制x或y轴
	bool bXCoordiate = false;

	int8 SelectLine = -1;

	TArray<FLine> XLines;

	TArray<FLine> YLines;
};